package GUI;
/**
 * Attribute class to course screen 
 * for the administrator
 */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;

import Common.Course;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class AttributeClassToCourseSelCrs extends JPanel {
	private JLabel label = null;
	private JLabel label_1 = null;
	private JComboBox cBSelCourse = null;
	private JButton btnNext = null;
	
	public Login myLoginFrame = null;
	public UserAdmin user=null;
	public AdminMainMenu amn=null;	
	
	private String selCourse = null;
	private AttributeClassToCourse ClsToCrs = null;
	
	
	public JComboBox getcBSelCourse(AdminMainMenu amn)
	{
		int i,j;
		Vector<CourseOfClass> data1 = new Vector<CourseOfClass>();
		Vector<RawCourse> data = new Vector<RawCourse>();
		Vector<String> convert = new Vector<String>();
		
		//All the courses available
		for(i=0;i<amn.user.dataAttClassToCourse.RawCourses.size();i++)
		{ 
			
			data.add(amn.user.dataAttClassToCourse.RawCourses.get(i));
			System.out.println("Available Courses "+amn.user.dataAttClassToCourse.RawCourses.get(i).Cid);
			
		}
		System.out.println("Try "+amn.user.dataAttClassToCourse.CoursesThatClassTaked.get(0).Cid);
		System.out.println("Size of "+amn.user.dataAttClassToCourse.CoursesThatClassTaked.size());
		System.out.println("Class chosen "+amn.user.dataAttClassToCourse.getSelClass());
	
		//All the courses that our class took
		for(i=0;i<amn.user.dataAttClassToCourse.CoursesThatClassTaked.size();i++)
		{
			if(amn.user.dataAttClassToCourse.CoursesThatClassTaked.get(i).ClassID.equals(amn.user.dataAttClassToCourse.getSelClass()))
			{
				data1.add(amn.user.dataAttClassToCourse.CoursesThatClassTaked.get(i));
				System.out.println("Courses that our class took "+amn.user.dataAttClassToCourse.CoursesThatClassTaked.get(i).Cid);
			}
			
		}
			
	
		for(i=0;i<data1.size();i++)
		{
			for(j=0;j<data.size();j++)
			{
				
				
				if(data.get(j).Cid.equals(data1.get(i).Cid))
				{
					data.remove(j);
				}
			}
		}
		
		
		
		
		
		for(i=0;i<data.size();i++)
		{
			convert.add(data.get(i).CourseName+" "+data.get(i).Cid);
			 System.out.println("Test1: "+data.get(i).Cid+" "+data.get(i).CourseName );
				
			
		}
		

		if(cBSelCourse==null)
		{
			cBSelCourse = new JComboBox(convert);
			cBSelCourse.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selCourse=cBSelCourse.getSelectedItem().toString();
			 		System.out.println(selCourse);
					
					
				}
			});
			cBSelCourse.setBounds(256, 77, 178, 20);
		}
		return cBSelCourse;
	}
	
	
	public JButton getBtnNext(final AdminMainMenu amn)
	{
		if(btnNext==null)
		{
		btnNext = new JButton("Next");
		btnNext.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				amn.user.dataAttClassToCourse.setSelCourse(selCourse);
				ClsToCrs = null;
				ClsToCrs = amn.getClsToCrs();
				amn.setContentPane(ClsToCrs);
			}
		});
		btnNext.setBounds(517, 315, 89, 23);
		}
		
		return  btnNext ;
		
	}
	
	public void initialize(AdminMainMenu amn)
	{
		setLayout(null);
		
		label = new JLabel("Attribute Class to Course");
		label.setBounds(129, 11, 192, 14);
		add(label);
		
		label_1 = new JLabel("Select course:");
		label_1.setBounds(64, 80, 138, 14);
		add(label_1);
		add(getcBSelCourse(amn));
		add(getBtnNext(amn));
		
	}
	
	
	
	
	
	public AttributeClassToCourseSelCrs(AdminMainMenu amn) {
		super();
		initialize(amn);
		
	}
}
